<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="arr"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
        v-model="sms"
        center
        clearable
        label="短信验证码"
        placeholder="请输入短信验证码"
      >
        <template #button>
          <van-button size="small" type="primary"  color="linear-gradient(to right, #ff6034, #ee0a24)">发送验证码</van-button>
        </template>
        <template #left-icon>
          <van-icon name="service-o" />
        </template>
      </van-field>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
const userHandle = (value, rule) => {
  //第一个输出的就是 输入的值,第二个就是 正个对象
  console.log(value, rule, 8888)
  var reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
  var flag = reg.test(value)
  return flag

}
export default {
  data () {
    return {
      username: '',
      password: '',
      sms: '',
      arr: [{ required: true, message: '请填写用户名' },
      // { pattern: /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/, message: '正确手机' }
      //函数方式校验
      { validator: userHandle, message: '请填写合法手机号' }
      ]
    };
  },
  methods: {
    onSubmit (values) {
      console.log('submit', values);
    },
  },
};
</script>
<style lang='less'  scoped>
</style>
